package a66weding.com.jiehuntong.activity.order.adapter;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.x;

import java.util.List;
import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.activity.me.MeIndentEvaluateActivity;
import a66weding.com.jiehuntong.adapter.MyBaseAdapter;
import a66weding.com.jiehuntong.beans.MyOrderBean;
import a66weding.com.jiehuntong.common.utils.ImageOptionsUtil;
import a66weding.com.jiehuntong.inner.IsEvaluationInner;
import a66weding.com.jiehuntong.widgets.CustomImageView;


/**
 * Created by admin on 2016/8/30.
 */
public class EvaluationAdapter extends MyBaseAdapter{

    public EvaluationAdapter(Context context, List data) {
        super(context, data);
    }

    int flag = -1 ;

    public void setFlag(int flag) {
        this.flag = flag;
        notifyDataSetChanged();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView==null){
            convertView = View.inflate(context, R.layout.item_evaluation,null);
            holder = new ViewHolder();
            holder.item_elt_iamge = (CustomImageView) convertView.findViewById(R.id.item_elt_iamge);
            holder.item_elt_tv = (TextView) convertView.findViewById(R.id.item_elt_tv);
            holder.item_evaluation_shap = (TextView) convertView.findViewById(R.id.item_evaluation_shap);
            holder.item_evaluation_r = (TextView) convertView.findViewById(R.id.item_evaluation_r);
            convertView.setTag(holder);

        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        final MyOrderBean.DataBean.MyOrderDetailBean orderDetailBean = (MyOrderBean.DataBean.MyOrderDetailBean) data.get(position);
        if (orderDetailBean!=null){
            x.image().bind(holder.item_elt_iamge,orderDetailBean.getProductPicMain(), ImageOptionsUtil.getOptions316_720());
            holder.item_evaluation_r.setText("数量 :"+orderDetailBean.getBuyNumber());
            holder.item_evaluation_shap.setText(orderDetailBean.getProductName());
        }

        if (position==flag){
            holder.item_elt_tv.setVisibility(View.GONE);
        }
        holder.item_elt_tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, MeIndentEvaluateActivity.class);
                    intent.putExtra("EvaluationAdapter",orderDetailBean);
                    intent.putExtra("flag",position);
                    context.startActivity(intent);
                }
            });

        return convertView;
    }

    public class ViewHolder{
        //图片;
        CustomImageView item_elt_iamge;
        //按钮;
        TextView item_elt_tv;
        //内容
        TextView item_evaluation_shap;
        //数量
        TextView item_evaluation_r;
    }
}
